package com.turing.data.scripts.yhjftzd.filter

import com.turing.common.util.Log
import com.turing.common.util.StringUtils
import com.turing.common.util.Tools
import com.turing.data.engine.utils.ScriptsUtils
import com.turing.data.vo.out.review.DependParamsVO
import com.turing.data.vo.out.review.TaskElementVO

/**
 * 场景名称: 外汇缴费通知单
 * 要素名称: 回购交易汇总（手续费净额）
 * @author: fanyihang
 */

class RepoTransactionSummary_30265_66_filter {

    static List<TaskElementVO.DrawResultVO> doConvert(DependParamsVO dependParams) {

        List<TaskElementVO.DrawResultVO> trueValueSet = new ArrayList<>()

        //与融资类交易-1天（手续费净额）和融资类交易-2天及以上（手续费净额）相关联
        def relatedMap = dependParams.relatedBusiElements
        def relatedObject1 = new TaskElementVO.DrawResultVO()
        def relatedObject2 = new TaskElementVO.DrawResultVO()
        if(Tools.isNotEmpty(relatedMap.get("融资类交易-1天（手续费净额）"))){
            relatedObject1 = relatedMap.get("融资类交易-1天（手续费净额）").get(0)
        }
        if(Tools.isNotEmpty(relatedMap.get("融资类交易-2天及以上（手续费净额）"))){
            relatedObject2 = relatedMap.get("融资类交易-2天及以上（手续费净额）").get(0)
        }

        TaskElementVO.DrawResultVO defaultDrawResultVO = new TaskElementVO.DrawResultVO()
        if (relatedObject1 != null && !StringUtils.isEmpty(relatedObject1.text) && relatedObject2 != null && !StringUtils.isEmpty(relatedObject2.text)) {
            //取符号变成int类型
            int transaction1 = relatedObject1.text.replaceAll(/[,.，。、]/, "") as int
            int transaction2 = relatedObject2.text.replaceAll(/[,.，。、]/, "") as int
            int total = transaction2 + transaction1
            //对计算结果加入字符
            defaultDrawResultVO.text = getFigure(total as String)
            trueValueSet.add(defaultDrawResultVO)
            return trueValueSet
        } else if(StringUtils.isEmpty(relatedObject1.text) && relatedObject2 != null && !StringUtils.isEmpty(relatedObject2.text)){
            defaultDrawResultVO.text = relatedObject2.text
            trueValueSet.add(defaultDrawResultVO)
            return trueValueSet
        }else if(StringUtils.isEmpty(relatedObject2.text) && relatedObject1 != null && !StringUtils.isEmpty(relatedObject1.text)){
            defaultDrawResultVO.text = relatedObject1.text
            trueValueSet.add(defaultDrawResultVO)
            return trueValueSet
        }

        //返回空字符串
        defaultDrawResultVO.text = ""
        trueValueSet.add(defaultDrawResultVO)
        return trueValueSet

    }

    //对小写金额进行处理
    static String getFigure (String total){
        //对未处理的小写金额进行处理
        if(total.contains(",")||total.contains(".")){
            return total
        }else{
            String modelValue = total
            String result = ""
            //获得末尾两个数字
            String endNum = modelValue.substring(modelValue.length()-2,modelValue.length())
            //除去末尾两个数字
            String str2 = modelValue.substring(0,modelValue.length()-2)
            // 逆转
            String str3 = str2.reverse()
            //转化为数组进行遍历
            def arr = str3.toCharArray()
            //定义一个空字符串
            def ture = ""
            def num = 0
            for (i in arr) {
                num++
                if(num%3==0&&num!=arr.length){
                    println ("num"+num)
                    ture = ture+i+","
                }else{
                    ture = ture+i
                }
            }
            //进行反转 和 加上.00
            result = ture.reverse().concat(".").concat(endNum)
            return result
        }
    }

}
